<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>事件委托</title>
</head>

<body>
    <ul id="ul">
        <li>1</li>
        <li>2</li>
        <li>3</li>
    </ul>

    <script>
        let ul = document.getElementById('ul')

        ul.onclick = function(e){
            e.target.nodeName === "LI" && (e.target.style.background = 'red')
        }
    </script>
</body>

</html>